﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Warehouse_Bar_Code
{
    public partial class 仓库信息添加或修改 : Form
    {
        //用于窗体间传递值
        public int Id;
        public string DName;
        public string Phone;
        public 仓库信息 f;//桥梁
        public 仓库信息添加或修改()
        {
            InitializeComponent();
        }
        private void DepotAddAndEdit_Load(object sender, EventArgs e)
        {

            //初始化信息
            textBox1.Text = DName;
            textBox2.Text = Phone;
        }

        private void button1_Click(object sender, EventArgs e)
        {

            string DName = textBox1.Text;
            string Phone = textBox2.Text;
            string sql = $"insert into Depot values('{DName}','{Phone}')";
            if (DBH.NoSelect(sql) > 0)
            {
                MessageBox.Show("添加成功！");
                f.dataGridView1.AutoGenerateColumns = false;
                f.dataGridView1.DataSource = DBH.Select("select * from Depot");


            }
            else
            {
                MessageBox.Show("添加失败！");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "")
            {
                MessageBox.Show("仓库名或电话不能为空");
            }
            else
            {
                //获取最新值
                string DName = textBox1.Text;
                string Phone = textBox2.Text;


                string sql = $"update Depot set DName='{1}',Phone='{2}' where id={Id}";
                if (DBH.NoSelect(sql) > 0)
                {
                    MessageBox.Show("保存成功！");
                    f.dataGridView1.AutoGenerateColumns = false;
                    f.dataGridView1.DataSource = DBH.Select("select * from Depot");
                }
                else
                {
                    MessageBox.Show("修改失败！");
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
